package co.com.services.matricula;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.MatriculaDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartMatriculaService")
public class MatriculaService {
	@GET
	@Path("/getAllMatricula")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getMatricula() throws NamingException{
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().consultarAllMatricula())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getMatriculaId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getMatriculaId(MatriculaDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().consultarMatriculaId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setMatricula")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setMatricula( MatriculaDTO json){ 
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().insertarMatricula(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editMatricula")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditMatricula(MatriculaDTO json){ 
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().editMatricula(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeMatricula")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveMatricula(MatriculaDTO json){ 
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().removeMatricula(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/consultarMatricula")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getConsultarMatricula(MatriculaDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getMatriculaBeanLocal().consultarMatricula(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
}
